package com.czxy.tanhua.controller;

import com.czxy.tanhua.entity.UserInfo;
import com.czxy.tanhua.interceptor.UserHolder;
import com.czxy.tanhua.service.UserService;
import com.czxy.tanhua.vo.BlackListVo;
import com.czxy.tanhua.vo.ResultList;
import com.czxy.tanhua.vo.SettingsVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author 爱吃豆的土豆、
 * @Date 2023/4/4 11:29
 */
@RequestMapping("/users")
@RestController
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 获得用户信息
     * @return
     */
    @GetMapping
    public ResponseEntity finduserByPhone(){
        Long userId = UserHolder.getUserId();
        UserInfo userInfo = userService.finduserById(userId);
        return ResponseEntity.ok(userInfo);
    }
    /**
     * 修改用户信息
     */
    @PutMapping
    public ResponseEntity editUser(@RequestBody UserInfo userInfo){
        //解析出来Jwt用户密码
        userService.editUser(userInfo,UserHolder.getUserId());
        return ResponseEntity.ok(null);
    }
    /**
     * 更新头像
     */
    @PostMapping("/header")
    public ResponseEntity editheader(MultipartFile headPhoto){
        userService.editheader(headPhoto,UserHolder.getUserId());
        return ResponseEntity.ok(null);
    }
    @GetMapping("/settings")
    public ResponseEntity findUsersettings(){
        SettingsVo usersettings = userService.findUsersettings(UserHolder.getUserId());
        usersettings.setPhone(UserHolder.getMobile());
        return ResponseEntity.ok(usersettings);
    }
    @PostMapping("/questions")
    public ResponseEntity editquestion(@RequestBody Map content){
        userService.editquestion(String.valueOf(content.get("content")), UserHolder.getUserId());
        return ResponseEntity.ok(null);
    }
    @PostMapping("/notifications/setting")
    public ResponseEntity editsetting(@RequestBody SettingsVo settingsVo){
        userService.editsetting(settingsVo,UserHolder.getUserId());
        return ResponseEntity.ok(null);
    }
    @GetMapping("/blacklist")
    public ResponseEntity findblacklist(BlackListVo blackListVo){
        System.out.println(blackListVo);
        ResultList findblacklist = userService.findblacklist(blackListVo,UserHolder.getUserId());
        return ResponseEntity.ok(findblacklist);
    }
    /**
     * 移除黑名单
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteblack(@PathVariable("uid") Long uid){
        userService.deleteblack(uid);
        return ResponseEntity.ok(null);
    }
}
